package website.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import website.constants.Code;
import website.domain.ResModel;
import website.domain.WebInfo;
import website.mapper.WebMapper;
import website.service.WebService;

import javax.annotation.Resource;

@Service
public class WebServiceImpl extends ServiceImpl<WebMapper, WebInfo> implements WebService {

    @Resource
    private WebMapper webMapper;

    @Value("${website.id}")
    private Integer id;


    /**
     * 查询网站信息
     * @return
     */
    @Override
    public ResModel<WebInfo> getWebInfo() {
        return ResModel.success(Code.SUCCESS,getById(id));
    }

    /**
     * 发布网站公告
     * @param webInfo
     * @return
     */
    @Override
    public ResModel issue(WebInfo webInfo) {
        if (webInfo.getNotice()!=null){
            webInfo.setId(id);
            boolean b = updateById(webInfo);
            return ResModel.success(Code.ISSUE,b);
        }
        return ResModel.error(Code.FAIL);
    }
}
